import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib.cm as cm

import matplotlib as mpl



def create_localgridcoords(elev):
    irow=np.arange(elev.shape[1])
    icol=np.arange(elev.shape[0])
    return np.meshgrid(irow,icol[::-1])
    
    
    
def generate_basemap(which_basemap):
    path_to_file='/home/eglsais/Dropbox/Thesis/csv_files_originals/'
    dat_list=['DEM','Lith', 'grad_n3', 'asp_n3']
    dat_type_list=['np.float','np.int','np.float','np.float']

    dat_name=dat_list[which_basemap]
    dat=np.genfromtxt(path_to_file+dat_name, missing_values='nan',skip_header=6)

    if which_basemap==1:
        dat=np.where((dat>=1)*(dat<=5),dat,np.nan)

    return dat


def plot_basemap(which_basemap,basemap):
    if which_basemap==1:
    
        cmap = mpl.colors.ListedColormap(['b','g','r','c','m'])
        bounds=[0.5,1.5,2.5,3.5,4.5,5.5]
        norm = mpl.colors.BoundaryNorm(bounds, cmap.N)

        plt.imshow(basemap,interpolation='nearest',
                   cmap = cmap,norm=norm,alpha=0.3)

    else:
        plt.imshow(dat, alpha=0.3)

        
    plt.axis('equal')

    return 

def plot_on_basemap(df,nc,mincol,maxcol,s,lw):

    df['_Y']=df.index.values/nc
    df['_X']=df.index.values-df._Y.values*nc

    Y=df._Y.values
    X=df._X.values

    col=df.FS_pcF.values
    plt.scatter(X[np.argsort(col)],Y[np.argsort(col)],s=s,
                c=np.sort(col),vmin=mincol,vmax=maxcol,cmap=cm.jet,linewidth=lw)
















